/*
package com.tianji.aigc.service.impl;

import cn.hutool.extra.spring.SpringUtil;
import com.tianji.aigc.agent.AbstractAgent;
import com.tianji.aigc.agent.Agent;
import com.tianji.aigc.domain.vo.ChatEventVO;
import com.tianji.aigc.enums.AgentTypeEnum;
import com.tianji.aigc.enums.ChatEventTypeEnum;
import com.tianji.aigc.service.IChatService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;


//@Service
@RequiredArgsConstructor
@Slf4j
public class AgentServiceImpl implements IChatService {
    */
/**
     * 聊天
     * @param question  问题
     * @param sessionId 会话id
     * @return 聊天结果
     *//*

    @Override
    public Flux<ChatEventVO> chat(String question, String sessionId) {
        // 实现思路：先把问题发给路由智能体，然后根据路由结果，调用对应的智能体进行处理
        String result = this.findAgentByType(AgentTypeEnum.ROUTE).process(question, sessionId);
        AgentTypeEnum agentTypeEnum = AgentTypeEnum.agentNameOf(result);
        // 添加空值检查并完善日志
        if (agentTypeEnum == null) {
            log.warn("路由结果无法匹配到智能体类型，路由结果: {}", result);
            ChatEventVO chatEventVO = ChatEventVO.builder()
                    .eventType(ChatEventTypeEnum.DATA.getValue())
                    .eventData(result)
                    .build();
            return Flux.just(chatEventVO, AbstractAgent.STOP_EVENT);
        }
        log.debug("当前使用智能体是===>：{}", agentTypeEnum.getAgentName());
        Agent agent = this.findAgentByType(agentTypeEnum);
        if (agent == null) {
            // 找不到对应的智能体，直接返回结果
            ChatEventVO chatEventVO = ChatEventVO.builder()
                    .eventType(ChatEventTypeEnum.DATA.getValue())
                    .eventData(result)
                    .build();
            return Flux.just(chatEventVO, AbstractAgent.STOP_EVENT);
        }
        // 执行智能体的逻辑
        return agent.processStream(question, sessionId);
    }

    */
/**
     * 根据智能体类型,找到对应的智能体
     * @param agentTypeEnum 智能体类型
     * @return 智能体
     *//*

    private Agent findAgentByType(AgentTypeEnum agentTypeEnum) {
        if (agentTypeEnum == null){
            return null;
        }
        // 获取所有Agent Bean
        var beans = SpringUtil.getBeansOfType(Agent.class);
        // 遍历所有Agent Bean查找匹配类型
        for (Agent agent : beans.values()) {
            if (agentTypeEnum == agent.getAgentType()) {
                return agent;
            }
        }
        return null;
    }

    */
/**
     * 停止会话
     * @param sessionId 会话id
     *//*

    @Override
    public void stopChat(String sessionId) {
        this.findAgentByType(AgentTypeEnum.ROUTE).stop(sessionId);
    }
}
*/
